{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>名称</th>\n",
       "      <th>PB</th>\n",
       "      <th>5%分位</th>\n",
       "      <th>PB最小</th>\n",
       "      <th>PB最大</th>\n",
       "      <th>PB中位数</th>\n",
       "      <th>PB标准差</th>\n",
       "      <th>PE</th>\n",
       "      <th>5%分位</th>\n",
       "      <th>PE最小</th>\n",
       "      <th>PE最大</th>\n",
       "      <th>PE中位数</th>\n",
       "      <th>PE标准差</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>000001.XSHG</th>\n",
       "      <td>上证指数</td>\n",
       "      <td>1.22</td>\n",
       "      <td>1.323</td>\n",
       "      <td>1.21('2014/5/7')</td>\n",
       "      <td>7.14('2007/10/15')</td>\n",
       "      <td>1.91</td>\n",
       "      <td>1.098</td>\n",
       "      <td>11.80</td>\n",
       "      <td>10.420</td>\n",
       "      <td>9.04('2014/4/28')</td>\n",
       "      <td>72.54('2007/10/15')</td>\n",
       "      <td>17.560</td>\n",
       "      <td>11.468</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000300.XSHG</th>\n",
       "      <td>沪深300</td>\n",
       "      <td>1.24</td>\n",
       "      <td>1.300</td>\n",
       "      <td>1.17('2014-05-07')</td>\n",
       "      <td>7.46('2007-10-16')</td>\n",
       "      <td>1.78</td>\n",
       "      <td>1.214</td>\n",
       "      <td>10.92</td>\n",
       "      <td>9.312</td>\n",
       "      <td>8.18('2014-05-19')</td>\n",
       "      <td>65.63('2007-10-31')</td>\n",
       "      <td>14.235</td>\n",
       "      <td>10.333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000905.XSHG</th>\n",
       "      <td>中证500</td>\n",
       "      <td>1.52</td>\n",
       "      <td>1.860</td>\n",
       "      <td>1.44('2008-11-04')</td>\n",
       "      <td>5.89('2015-06-15')</td>\n",
       "      <td>2.79</td>\n",
       "      <td>0.895</td>\n",
       "      <td>17.54</td>\n",
       "      <td>22.107</td>\n",
       "      <td>17.54('2019-01-03')</td>\n",
       "      <td>103.75('2008-01-15')</td>\n",
       "      <td>38.690</td>\n",
       "      <td>19.228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399001.XSHE</th>\n",
       "      <td>深证成指</td>\n",
       "      <td>1.96</td>\n",
       "      <td>1.850</td>\n",
       "      <td>1.67('2005-11-15')</td>\n",
       "      <td>8.82('2007-10-16')</td>\n",
       "      <td>2.82</td>\n",
       "      <td>1.262</td>\n",
       "      <td>17.40</td>\n",
       "      <td>12.413</td>\n",
       "      <td>10.61('2005-07-11')</td>\n",
       "      <td>63.44('2007-10-16')</td>\n",
       "      <td>21.920</td>\n",
       "      <td>11.136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399005.XSHE</th>\n",
       "      <td>中小板指</td>\n",
       "      <td>2.58</td>\n",
       "      <td>3.062</td>\n",
       "      <td>2.39('2008-11-04')</td>\n",
       "      <td>8.17('2007-10-10')</td>\n",
       "      <td>4.20</td>\n",
       "      <td>1.157</td>\n",
       "      <td>20.45</td>\n",
       "      <td>23.440</td>\n",
       "      <td>19.44('2008-10-27')</td>\n",
       "      <td>80.41('2008-01-15')</td>\n",
       "      <td>34.910</td>\n",
       "      <td>11.791</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399006.XSHE</th>\n",
       "      <td>创业板指</td>\n",
       "      <td>3.43</td>\n",
       "      <td>3.050</td>\n",
       "      <td>2.51('2012-12-03')</td>\n",
       "      <td>15.01('2015-06-03')</td>\n",
       "      <td>4.80</td>\n",
       "      <td>1.946</td>\n",
       "      <td>31.10</td>\n",
       "      <td>33.220</td>\n",
       "      <td>27.99('2012-12-03')</td>\n",
       "      <td>139.96('2015-06-03')</td>\n",
       "      <td>55.660</td>\n",
       "      <td>19.446</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399016.XSHE</th>\n",
       "      <td>深证创新指数</td>\n",
       "      <td>2.57</td>\n",
       "      <td>2.790</td>\n",
       "      <td>2.57('2019-01-03')</td>\n",
       "      <td>4.79('2017-11-13')</td>\n",
       "      <td>4.16</td>\n",
       "      <td>0.551</td>\n",
       "      <td>18.33</td>\n",
       "      <td>19.826</td>\n",
       "      <td>18.33('2019-01-03')</td>\n",
       "      <td>40.29('2017-11-13')</td>\n",
       "      <td>33.285</td>\n",
       "      <td>5.988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399300.XSHE</th>\n",
       "      <td>沪深300</td>\n",
       "      <td>1.24</td>\n",
       "      <td>1.300</td>\n",
       "      <td>1.17('2014-05-07')</td>\n",
       "      <td>7.46('2007-10-16')</td>\n",
       "      <td>1.79</td>\n",
       "      <td>1.214</td>\n",
       "      <td>10.92</td>\n",
       "      <td>9.312</td>\n",
       "      <td>8.18('2014-05-19')</td>\n",
       "      <td>65.63('2007-10-31')</td>\n",
       "      <td>14.260</td>\n",
       "      <td>10.332</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399975.XSHE</th>\n",
       "      <td>中证全指证券公司指数(四级行业)</td>\n",
       "      <td>1.32</td>\n",
       "      <td>1.338</td>\n",
       "      <td>1.1('2018/10/18')</td>\n",
       "      <td>6.11('2015/6/8')</td>\n",
       "      <td>2.44</td>\n",
       "      <td>0.988</td>\n",
       "      <td>40.97</td>\n",
       "      <td>15.477</td>\n",
       "      <td>12.4('2015/9/15')</td>\n",
       "      <td>82.1('2013/9/12')</td>\n",
       "      <td>37.290</td>\n",
       "      <td>14.495</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399368.XSHE</th>\n",
       "      <td>国证军工</td>\n",
       "      <td>2.76</td>\n",
       "      <td>2.780</td>\n",
       "      <td>2.22('2012/12/3')</td>\n",
       "      <td>11.33('2015/6/2')</td>\n",
       "      <td>4.21</td>\n",
       "      <td>1.517</td>\n",
       "      <td>69.35</td>\n",
       "      <td>70.493</td>\n",
       "      <td>59.6('2018/10/29')</td>\n",
       "      <td>326.97('2018/1/10')</td>\n",
       "      <td>133.360</td>\n",
       "      <td>49.503</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399959.XSHE</th>\n",
       "      <td>军工指数</td>\n",
       "      <td>2.59</td>\n",
       "      <td>2.883</td>\n",
       "      <td>2.42('2012/12/3')</td>\n",
       "      <td>13.06('2015/6/2')</td>\n",
       "      <td>4.15</td>\n",
       "      <td>1.925</td>\n",
       "      <td>73.90</td>\n",
       "      <td>81.645</td>\n",
       "      <td>65.21('2018/10/19')</td>\n",
       "      <td>333.38('2015/6/12')</td>\n",
       "      <td>145.805</td>\n",
       "      <td>54.677</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399967.XSHE</th>\n",
       "      <td>中证军工</td>\n",
       "      <td>2.96</td>\n",
       "      <td>3.303</td>\n",
       "      <td>2.89('2018/10/30')</td>\n",
       "      <td>13.37('2015/6/2')</td>\n",
       "      <td>5.90</td>\n",
       "      <td>1.976</td>\n",
       "      <td>52.84</td>\n",
       "      <td>59.727</td>\n",
       "      <td>49.07('2018/10/19')</td>\n",
       "      <td>979.83('2015/11/26')</td>\n",
       "      <td>151.990</td>\n",
       "      <td>183.414</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>399241.XSHE</th>\n",
       "      <td>地产指数</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.321</td>\n",
       "      <td>1.6('2018/10/18')</td>\n",
       "      <td>171.13('2014/12/5')</td>\n",
       "      <td>4.25</td>\n",
       "      <td>25.461</td>\n",
       "      <td>NaN</td>\n",
       "      <td>33.898</td>\n",
       "      <td>16.98('2018/9/28')</td>\n",
       "      <td>464.15('2015/11/23')</td>\n",
       "      <td>83.015</td>\n",
       "      <td>69.211</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000015.XSHG</th>\n",
       "      <td>红利指数</td>\n",
       "      <td>1.42</td>\n",
       "      <td>1.570</td>\n",
       "      <td>1.26('2018/11/28')</td>\n",
       "      <td>10.37('2007/9/10')</td>\n",
       "      <td>2.17</td>\n",
       "      <td>1.501</td>\n",
       "      <td>13.31</td>\n",
       "      <td>11.099</td>\n",
       "      <td>6.23('2008/11/4')</td>\n",
       "      <td>168.03('2016/10/25')</td>\n",
       "      <td>20.000</td>\n",
       "      <td>17.738</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000016.XSHG</th>\n",
       "      <td>上证50</td>\n",
       "      <td>2.10</td>\n",
       "      <td>1.860</td>\n",
       "      <td>1.62('2018/6/1')</td>\n",
       "      <td>5.22('2015/6/8')</td>\n",
       "      <td>2.24</td>\n",
       "      <td>0.600</td>\n",
       "      <td>17.19</td>\n",
       "      <td>18.890</td>\n",
       "      <td>15.8('2011/12/27')</td>\n",
       "      <td>394.56('2015/4/14')</td>\n",
       "      <td>25.250</td>\n",
       "      <td>62.944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000813.XSHG</th>\n",
       "      <td>细分化工</td>\n",
       "      <td>1.83</td>\n",
       "      <td>2.168</td>\n",
       "      <td>1.8('2018-11-26')</td>\n",
       "      <td>7.59('2015-06-12')</td>\n",
       "      <td>2.92</td>\n",
       "      <td>0.898</td>\n",
       "      <td>16.85</td>\n",
       "      <td>20.326</td>\n",
       "      <td>15.82('2018-10-26')</td>\n",
       "      <td>555.27('2015-08-19')</td>\n",
       "      <td>46.770</td>\n",
       "      <td>73.654</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000814.XSHG</th>\n",
       "      <td>细分医药</td>\n",
       "      <td>4.18</td>\n",
       "      <td>4.540</td>\n",
       "      <td>4.07('2018-10-18')</td>\n",
       "      <td>10.8('2015-06-15')</td>\n",
       "      <td>5.80</td>\n",
       "      <td>1.021</td>\n",
       "      <td>25.22</td>\n",
       "      <td>31.822</td>\n",
       "      <td>24.83('2018-10-18')</td>\n",
       "      <td>158.26('2013-05-30')</td>\n",
       "      <td>51.590</td>\n",
       "      <td>21.717</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000815.XSHG</th>\n",
       "      <td>细分食品</td>\n",
       "      <td>3.73</td>\n",
       "      <td>3.500</td>\n",
       "      <td>3.27('2013-06-27')</td>\n",
       "      <td>8.2('2015-06-30')</td>\n",
       "      <td>4.89</td>\n",
       "      <td>1.232</td>\n",
       "      <td>30.20</td>\n",
       "      <td>39.716</td>\n",
       "      <td>29.57('2018-12-19')</td>\n",
       "      <td>267.98('2012-04-11')</td>\n",
       "      <td>68.790</td>\n",
       "      <td>27.265</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000005.XSHG</th>\n",
       "      <td>商业指数</td>\n",
       "      <td>3.38</td>\n",
       "      <td>3.570</td>\n",
       "      <td>2.81('2018/10/18')</td>\n",
       "      <td>46.75('2016/1/11')</td>\n",
       "      <td>7.09</td>\n",
       "      <td>7.582</td>\n",
       "      <td>53.36</td>\n",
       "      <td>43.651</td>\n",
       "      <td>36.42('2018/10/18')</td>\n",
       "      <td>1033.25('2015/4/27')</td>\n",
       "      <td>83.295</td>\n",
       "      <td>94.086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000006.XSHG</th>\n",
       "      <td>地产指数</td>\n",
       "      <td>1.54</td>\n",
       "      <td>1.650</td>\n",
       "      <td>1.39('2012/8/21')</td>\n",
       "      <td>33.87('2014/6/5')</td>\n",
       "      <td>2.49</td>\n",
       "      <td>3.150</td>\n",
       "      <td>16.76</td>\n",
       "      <td>18.676</td>\n",
       "      <td>12.29('2018/10/19')</td>\n",
       "      <td>270.54('2015/6/12')</td>\n",
       "      <td>33.920</td>\n",
       "      <td>26.588</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000007.XSHG</th>\n",
       "      <td>公用指数</td>\n",
       "      <td>1.95</td>\n",
       "      <td>1.960</td>\n",
       "      <td>1.59('2012/12/3')</td>\n",
       "      <td>11.32('2014/12/29')</td>\n",
       "      <td>3.32</td>\n",
       "      <td>1.058</td>\n",
       "      <td>34.91</td>\n",
       "      <td>30.811</td>\n",
       "      <td>28.23('2014/1/20')</td>\n",
       "      <td>227.03('2012/5/23')</td>\n",
       "      <td>51.750</td>\n",
       "      <td>36.254</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000015.XSHG</th>\n",
       "      <td>红利指数</td>\n",
       "      <td>1.42</td>\n",
       "      <td>1.570</td>\n",
       "      <td>1.26('2018/11/28')</td>\n",
       "      <td>10.37('2007/9/10')</td>\n",
       "      <td>2.17</td>\n",
       "      <td>1.501</td>\n",
       "      <td>13.31</td>\n",
       "      <td>11.099</td>\n",
       "      <td>6.23('2008/11/4')</td>\n",
       "      <td>168.03('2016/10/25')</td>\n",
       "      <td>20.000</td>\n",
       "      <td>17.738</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000816.XSHG</th>\n",
       "      <td>细分地产</td>\n",
       "      <td>1.36</td>\n",
       "      <td>1.510</td>\n",
       "      <td>1.25('2018/10/18')</td>\n",
       "      <td>5.99('2015/6/12')</td>\n",
       "      <td>2.47</td>\n",
       "      <td>0.712</td>\n",
       "      <td>10.93</td>\n",
       "      <td>14.350</td>\n",
       "      <td>10.56('2018/10/31')</td>\n",
       "      <td>256.51('2012/5/8')</td>\n",
       "      <td>36.890</td>\n",
       "      <td>41.021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000948.XSHG</th>\n",
       "      <td>内地地产</td>\n",
       "      <td>1.34</td>\n",
       "      <td>1.630</td>\n",
       "      <td>1.2('2018/10/30')</td>\n",
       "      <td>6.63('2009/12/10')</td>\n",
       "      <td>2.76</td>\n",
       "      <td>0.868</td>\n",
       "      <td>15.22</td>\n",
       "      <td>16.610</td>\n",
       "      <td>10.2('2018/10/30')</td>\n",
       "      <td>363.9('2012/6/18')</td>\n",
       "      <td>34.070</td>\n",
       "      <td>43.148</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000043.XSHG</th>\n",
       "      <td>超大盘</td>\n",
       "      <td>2.51</td>\n",
       "      <td>1.910</td>\n",
       "      <td>1.77('2016/6/24')</td>\n",
       "      <td>6.09('2015/6/15')</td>\n",
       "      <td>2.45</td>\n",
       "      <td>0.600</td>\n",
       "      <td>17.77</td>\n",
       "      <td>14.121</td>\n",
       "      <td>12.88('2012/8/29')</td>\n",
       "      <td>99.99('2015/6/15')</td>\n",
       "      <td>23.470</td>\n",
       "      <td>16.719</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           名称    PB   5%分位                PB最小  \\\n",
       "code                                                             \n",
       "000001.XSHG              上证指数  1.22  1.323    1.21('2014/5/7')   \n",
       "000300.XSHG             沪深300  1.24  1.300  1.17('2014-05-07')   \n",
       "000905.XSHG             中证500  1.52  1.860  1.44('2008-11-04')   \n",
       "399001.XSHE              深证成指  1.96  1.850  1.67('2005-11-15')   \n",
       "399005.XSHE              中小板指  2.58  3.062  2.39('2008-11-04')   \n",
       "399006.XSHE              创业板指  3.43  3.050  2.51('2012-12-03')   \n",
       "399016.XSHE            深证创新指数  2.57  2.790  2.57('2019-01-03')   \n",
       "399300.XSHE             沪深300  1.24  1.300  1.17('2014-05-07')   \n",
       "399975.XSHE  中证全指证券公司指数(四级行业)  1.32  1.338   1.1('2018/10/18')   \n",
       "399368.XSHE              国证军工  2.76  2.780   2.22('2012/12/3')   \n",
       "399959.XSHE              军工指数  2.59  2.883   2.42('2012/12/3')   \n",
       "399967.XSHE              中证军工  2.96  3.303  2.89('2018/10/30')   \n",
       "399241.XSHE              地产指数   NaN  2.321   1.6('2018/10/18')   \n",
       "000015.XSHG              红利指数  1.42  1.570  1.26('2018/11/28')   \n",
       "000016.XSHG              上证50  2.10  1.860    1.62('2018/6/1')   \n",
       "000813.XSHG              细分化工  1.83  2.168   1.8('2018-11-26')   \n",
       "000814.XSHG              细分医药  4.18  4.540  4.07('2018-10-18')   \n",
       "000815.XSHG              细分食品  3.73  3.500  3.27('2013-06-27')   \n",
       "000005.XSHG              商业指数  3.38  3.570  2.81('2018/10/18')   \n",
       "000006.XSHG              地产指数  1.54  1.650   1.39('2012/8/21')   \n",
       "000007.XSHG              公用指数  1.95  1.960   1.59('2012/12/3')   \n",
       "000015.XSHG              红利指数  1.42  1.570  1.26('2018/11/28')   \n",
       "000816.XSHG              细分地产  1.36  1.510  1.25('2018/10/18')   \n",
       "000948.XSHG              内地地产  1.34  1.630   1.2('2018/10/30')   \n",
       "000043.XSHG               超大盘  2.51  1.910   1.77('2016/6/24')   \n",
       "\n",
       "                            PB最大  PB中位数   PB标准差     PE    5%分位  \\\n",
       "code                                                             \n",
       "000001.XSHG   7.14('2007/10/15')   1.91   1.098  11.80  10.420   \n",
       "000300.XSHG   7.46('2007-10-16')   1.78   1.214  10.92   9.312   \n",
       "000905.XSHG   5.89('2015-06-15')   2.79   0.895  17.54  22.107   \n",
       "399001.XSHE   8.82('2007-10-16')   2.82   1.262  17.40  12.413   \n",
       "399005.XSHE   8.17('2007-10-10')   4.20   1.157  20.45  23.440   \n",
       "399006.XSHE  15.01('2015-06-03')   4.80   1.946  31.10  33.220   \n",
       "399016.XSHE   4.79('2017-11-13')   4.16   0.551  18.33  19.826   \n",
       "399300.XSHE   7.46('2007-10-16')   1.79   1.214  10.92   9.312   \n",
       "399975.XSHE     6.11('2015/6/8')   2.44   0.988  40.97  15.477   \n",
       "399368.XSHE    11.33('2015/6/2')   4.21   1.517  69.35  70.493   \n",
       "399959.XSHE    13.06('2015/6/2')   4.15   1.925  73.90  81.645   \n",
       "399967.XSHE    13.37('2015/6/2')   5.90   1.976  52.84  59.727   \n",
       "399241.XSHE  171.13('2014/12/5')   4.25  25.461    NaN  33.898   \n",
       "000015.XSHG   10.37('2007/9/10')   2.17   1.501  13.31  11.099   \n",
       "000016.XSHG     5.22('2015/6/8')   2.24   0.600  17.19  18.890   \n",
       "000813.XSHG   7.59('2015-06-12')   2.92   0.898  16.85  20.326   \n",
       "000814.XSHG   10.8('2015-06-15')   5.80   1.021  25.22  31.822   \n",
       "000815.XSHG    8.2('2015-06-30')   4.89   1.232  30.20  39.716   \n",
       "000005.XSHG   46.75('2016/1/11')   7.09   7.582  53.36  43.651   \n",
       "000006.XSHG    33.87('2014/6/5')   2.49   3.150  16.76  18.676   \n",
       "000007.XSHG  11.32('2014/12/29')   3.32   1.058  34.91  30.811   \n",
       "000015.XSHG   10.37('2007/9/10')   2.17   1.501  13.31  11.099   \n",
       "000816.XSHG    5.99('2015/6/12')   2.47   0.712  10.93  14.350   \n",
       "000948.XSHG   6.63('2009/12/10')   2.76   0.868  15.22  16.610   \n",
       "000043.XSHG    6.09('2015/6/15')   2.45   0.600  17.77  14.121   \n",
       "\n",
       "                            PE最小                  PE最大    PE中位数    PE标准差  \n",
       "code                                                                      \n",
       "000001.XSHG    9.04('2014/4/28')   72.54('2007/10/15')   17.560   11.468  \n",
       "000300.XSHG   8.18('2014-05-19')   65.63('2007-10-31')   14.235   10.333  \n",
       "000905.XSHG  17.54('2019-01-03')  103.75('2008-01-15')   38.690   19.228  \n",
       "399001.XSHE  10.61('2005-07-11')   63.44('2007-10-16')   21.920   11.136  \n",
       "399005.XSHE  19.44('2008-10-27')   80.41('2008-01-15')   34.910   11.791  \n",
       "399006.XSHE  27.99('2012-12-03')  139.96('2015-06-03')   55.660   19.446  \n",
       "399016.XSHE  18.33('2019-01-03')   40.29('2017-11-13')   33.285    5.988  \n",
       "399300.XSHE   8.18('2014-05-19')   65.63('2007-10-31')   14.260   10.332  \n",
       "399975.XSHE    12.4('2015/9/15')     82.1('2013/9/12')   37.290   14.495  \n",
       "399368.XSHE   59.6('2018/10/29')   326.97('2018/1/10')  133.360   49.503  \n",
       "399959.XSHE  65.21('2018/10/19')   333.38('2015/6/12')  145.805   54.677  \n",
       "399967.XSHE  49.07('2018/10/19')  979.83('2015/11/26')  151.990  183.414  \n",
       "399241.XSHE   16.98('2018/9/28')  464.15('2015/11/23')   83.015   69.211  \n",
       "000015.XSHG    6.23('2008/11/4')  168.03('2016/10/25')   20.000   17.738  \n",
       "000016.XSHG   15.8('2011/12/27')   394.56('2015/4/14')   25.250   62.944  \n",
       "000813.XSHG  15.82('2018-10-26')  555.27('2015-08-19')   46.770   73.654  \n",
       "000814.XSHG  24.83('2018-10-18')  158.26('2013-05-30')   51.590   21.717  \n",
       "000815.XSHG  29.57('2018-12-19')  267.98('2012-04-11')   68.790   27.265  \n",
       "000005.XSHG  36.42('2018/10/18')  1033.25('2015/4/27')   83.295   94.086  \n",
       "000006.XSHG  12.29('2018/10/19')   270.54('2015/6/12')   33.920   26.588  \n",
       "000007.XSHG   28.23('2014/1/20')   227.03('2012/5/23')   51.750   36.254  \n",
       "000015.XSHG    6.23('2008/11/4')  168.03('2016/10/25')   20.000   17.738  \n",
       "000816.XSHG  10.56('2018/10/31')    256.51('2012/5/8')   36.890   41.021  \n",
       "000948.XSHG   10.2('2018/10/30')    363.9('2012/6/18')   34.070   43.148  \n",
       "000043.XSHG   12.88('2012/8/29')    99.99('2015/6/15')   23.470   16.719  "
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#-*-coding:utf-8 -*-\n",
    "#所有需要的库文件添加该处\n",
    "import pandas as pd\n",
    "from six import StringIO\n",
    "import matplotlib.pyplot as plt\n",
    "import  numpy as np\n",
    "import os\n",
    "from datetime import datetime,timedelta\n",
    "from pyecharts import Line,Kline,Bar,Overlap,Grid\n",
    "from jqdatasdk import *\n",
    "import requests\n",
    "import tushare as ts\n",
    "pd.set_option('precision',3)\n",
    "\n",
    "#============一下为指数估值分析\n",
    "#所用文件目录如下：\n",
    "stock_basic_info_dir = \"C:\\\\quanttime\\\\data\\\\basic_info\\\\all_stock_info.csv\"\n",
    "index_basic_info_dir = \"C:\\\\quanttime\\\\data\\\\basic_info\\\\index_all_info_for_analyse.csv\"\n",
    "index_valuation_dir = \"C:\\\\quanttime\\\\data\\\\index\\\\index_valuation\\\\\"\n",
    "stock_valuation_dir = \"C:\\\\quanttime\\\\data\\\\finance\\\\valuation\\\\\"\n",
    "index_k_dir = \"C:\\\\quanttime\\\\data\\\\index\\\\jq\\\\\"\n",
    "\n",
    "#需要分析的指数添加到该list中\n",
    "analyse_index_list = [\"000001.XSHG\", \"000300.XSHG\", \"000905.XSHG\", \"399001.XSHE\",\\\n",
    "                      \"399005.XSHE\", \"399006.XSHE\", \"399016.XSHE\",\"399300.XSHE\",\\\n",
    "                      \"399975.XSHE\",\"399368.XSHE\",\"399959.XSHE\",\"399967.XSHE\",\"399241.XSHE\",\\\n",
    "                      \"000015.XSHG\",\"000016.XSHG\",\"000813.XSHG\",\"000814.XSHG\",\"000815.XSHG\",\\\n",
    "                     \"000005.XSHG\",\"000006.XSHG\",\"000007.XSHG\",\"000015.XSHG\",\"000816.XSHG\",\\\n",
    "                     \"000948.XSHG\",\"000043.XSHG\"]\n",
    "\n",
    "#加载index 基本信息\n",
    "df_index_info = pd.read_csv(index_basic_info_dir,index_col=[\"code\"],encoding=\"gbk\")\n",
    "#结果按照如下column排列：\n",
    "#code，名称，Pb，5%分位，PB_min，PB_max，PB_中值，PB_方差，Pe，5%分位，PE_min，PE_max，PE_均值，PE_方差\n",
    "general_result = []\n",
    "for index in analyse_index_list:\n",
    "    index_valuation = index_valuation_dir + index + '.csv'\n",
    "    #df_index_valuation = pd.read_csv(index_valuation,index_col=['date'])\n",
    "    #df_index_valuation = df_index_valuation[~df_index_valuation.reset_index().duplicated().values]\n",
    "    df_index_valuation = pd.read_csv(index_valuation)\n",
    "    df_index_valuation = df_index_valuation.drop_duplicates(\"date\")\n",
    "    df_index_valuation = df_index_valuation.set_index(\"date\")\n",
    "    \n",
    "    name = df_index_info.loc[index,['display_name']].display_name\n",
    "    pb = df_index_valuation.loc[df_index_valuation.index[len(df_index_valuation.index)-1],['PB']].PB\n",
    "    pb_quantile_5 = df_index_valuation.PB.quantile(0.05)\n",
    "    pb_min = '%r(%r)'%(df_index_valuation.PB.min(),df_index_valuation.PB.idxmin())\n",
    "    pb_max = '%r(%r)'%(df_index_valuation.PB.max(),df_index_valuation.PB.idxmax())\n",
    "    pb_median = df_index_valuation.PB.median()\n",
    "    pb_std = df_index_valuation.PB.std()\n",
    "    pe = df_index_valuation.loc[df_index_valuation.index[len(df_index_valuation.index)-1],['PE']].PE\n",
    "    pe_quantile_5 = df_index_valuation.PE.quantile(0.05)\n",
    "    pe_min = '%r(%r)'%(df_index_valuation.PE.min(),df_index_valuation.PE.idxmin())\n",
    "    pe_max = '%r(%r)'%(df_index_valuation.PE.max(),df_index_valuation.PE.idxmax())\n",
    "    pe_median = df_index_valuation.PE.median()\n",
    "    pe_std = df_index_valuation.PE.std()\n",
    "    general_result.append([name,pb,pb_quantile_5,pb_min,pb_max,pb_median,pb_std,pe,pe_quantile_5,pe_min,pe_max,pe_median,pe_std])\n",
    "df_columns=[u'名称', \"PB\", u'5%分位', u'PB最小', u'PB最大', u'PB中位数', u'PB标准差', \\\n",
    "                     \"PE\", u'5%分位', u'PE最小', u'PE最大', u'PE中位数', u'PE标准差']\n",
    "pe_df = pd.DataFrame(data=general_result,index=analyse_index_list,columns=df_columns)\n",
    "pe_df.index.name = \"code\"\n",
    "pe_df"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
